package leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class LC17 {

    public HashMap<Character,char[]> numMap = new HashMap<>();

    public List<String> getResult(String digits, List<String> ans,String digStr) {
        if (digits.length() <= 0) {
            ans.add(digStr);
            return ans;
        }

        char[] chars = numMap.get(digits.charAt(0));
        for (int i = 0; i < chars.length; i++) {
            String newDigit = digStr + chars[i];
            ans = getResult(digits.substring(1,digits.length()),ans,newDigit);
        }
        return ans;
    }


    public List<String> letterCombinations(String digits) {
        numMap.put('2', new char[]{'a', 'b', 'c'});
        numMap.put('3', new char[]{'d', 'e', 'f'});
        numMap.put('4', new char[]{'g', 'h', 'i'});
        numMap.put('5', new char[]{'j', 'k', 'l'});
        numMap.put('6', new char[]{'m', 'n', 'o'});
        numMap.put('7', new char[]{'p', 'q', 'r','s'});
        numMap.put('8', new char[]{'t', 'u', 'v'});
        numMap.put('9', new char[]{'w', 'x', 'y','z'});
        List<String> ans = new ArrayList<String>();
        if (digits.length() <= 0) return ans;
        ans = getResult(digits,ans,"");
        return ans;
    }


}
